<template>
  <ArmyPanelLayout class="TempComp" title="温湿度记录">
    <BtnGroupDevideTab style="margin: 8px 0 8px 21px;" :tabList="tabList" :tabActive="tabActive" @change="typeChangeAction"></BtnGroupDevideTab>
    <div class="TempComp--table" v-if="tableData.length && tabActive === 1">
      <div class="TempComp--table__header row">
        <div class="th one">仓库名称</div>
        <div class="th two">当前温度</div>
        <div class="th three">采集时间</div>
      </div>
      <div class="TempComp--table__body">
        <!--
        目标：设置 el-scrollbar 滚动，但是不允许用户滚动鼠标
        1. wrap-style="overflow:hidden" 不允许鼠标滚动
        2. view-style="height: 109px;overflow: hidden;" 不允许出现滚动条
        3. :always="false" 默认不显示滚动条
        -->
        <el-scrollbar height="110px" wrap-style="overflow:hidden" view-style="height: 109px;overflow: hidden;" :always="false">
          <div class="scrollbarlist">
            <div class="row" :class="{'two': (index % 2 !== 0)}" v-for="(item, index) in tableData"
                 :key="index">
              <div class="row--item one">{{ item.houseName }}</div>
              <div class="row--item two" style="color: #00E279;">{{ item.value }}</div>
              <div class="row--item three">{{ item.time }}</div>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
    <div class="TempComp--table" v-else-if="tableData.length && tabActive === 2">
      <div class="TempComp--table__header row">
        <div class="th one">仓库名称</div>
        <div class="th two">当前湿度</div>
        <div class="th three">采集时间</div>
      </div>
      <div class="TempComp--table__body">
          <el-scrollbar height="110px" wrap-style="overflow:hidden" view-style="height: 109px;overflow: hidden;" :always="false">
            <div class="scrollbarlist">
              <div class="row" :class="{'two': (index % 2 !== 0)}" v-for="(item, index) in tableData"
                   :key="index">
                <div class="row--item one">{{ item.houseName }}</div>
                <div class="row--item two" :style="item.redAlarm?'color:red':''">{{ item.value }}</div>
                <div class="row--item three">{{ item.time }}</div>
              </div>
            </div>
          </el-scrollbar>
      </div>
    </div>
    <div v-else class="empty" style="margin-top: 25%;">
      <DataEmptyTwo></DataEmptyTwo>
    </div>
  </ArmyPanelLayout>
</template>

<script>
import ArmyPanelLayout from '@/views/armyScreen/comp/ArmyPanelLayout.vue'
import BtnGroupDevideTab from '@/views/armyScreen/comp/BtnGroupDevideTab.vue'
import {ElScrollbar} from 'element-plus'
import {tempAndHumInfo} from '@/api/armyScreenApi.js'
import useCommonMethods from '@/mixin/useCommonMethods.js'
import DataEmptyTwo from "@/components/common/DataEmptyTwo.vue";
import $bus from "@/util/bus";

export default {
  inject: ['screenContext'],
  components: {
    DataEmptyTwo,
    ArmyPanelLayout,
    BtnGroupDevideTab,
  },
  data() {
    return {
      // 1-温度，2-湿度
      tabList: [
        {
          "dictCode": 1,
          "dictValue": "温度",
          "sort": 1,
          "value": 1,
          "label": "温度"
        },
        {
          "dictCode": 2,
          "dictValue": "湿度",
          "sort": 2,
          "value": 2,
          "label": "湿度"
        }
      ],
      tabActive: '',
      tableData: []
    }
  },
  setup() {
    const {dictByTypeService} = useCommonMethods()
    return {
      dictByTypeService
    }
  },
  async mounted() {
    if (this.tabList[0]) { // 需要从数据字典获取数据，如果没有类型，将无法展示
      this.tabActive = this.tabList[0].dictCode
      this.tempAndHumInfoService()
    }
    $bus.on('reRequest', this.tempAndHumInfoService)
  },
  beforeUnmount() {
    $bus.off('reRequest', this.tempAndHumInfoService)
  },
  methods: {
    // 获取颜色的样式
    getColorStr (str) {
      if (str === '已归还') {
        return 'color: #00E279;'
      } else if (str === '已借出') {
        return 'color: #EE4A45;'
      }
      return ''
    },
    tabChangeAction(value) {
      this.btnActive = value
      this.tempAndHumInfoService()
    },
    typeChangeAction(value) {
      this.tabActive = value
      this.tempAndHumInfoService()
    },
    tempAndHumInfoService() {
      const paramObj = {
        "valueType": this.tabActive,
      }
      tempAndHumInfo(paramObj).then(res => {
        this.tableData = res?.data?.list || []
      })
    },
    changeTab(tab) {
      this.tabActive = tab
      this.cameraOnOfflineBySchool()
    },
  }
}
</script>

<style lang="scss" scoped>
.TempComp {
  width: 439px;
  height: 100%;

  &--subtitle {
    width: 200px;
    line-height: 24px;
    margin-top: 10px;
  }

  &-tabList {
    margin: 16px 0 24px 21px;
    display: flex;
    justify-content: flex-start;

    &_item {
      cursor: pointer;
      height: 24px;
      padding: 0 10px;
      line-height: 24px;
      background-image: linear-gradient(270deg, rgba(0, 97, 165, 0.58) 0%, #0059A4 100%);
      border-radius: 2px;
      font-family: PingFangSC-Regular;
      font-size: 14px;
      color: rgba(167, 222, 255, 0.5);
      font-weight: 400;
      margin-right: 12px;
    }

    .selected {
      background-image: linear-gradient(270deg, rgba(17, 85, 152, 0.58) 0%, #00A3FA 100%);
      font-family: PingFangSC-Semibold;
      font-size: 14px;
      color: #C9EBFF;
      font-weight: 600;
    }
  }

  &--table {
    width: 420px;
    margin: 0 auto;

    .row {
      height: 28px;
      line-height: 28px;
      display: flex;

      div {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      .one {
        width: 90px;
      }

      .two {
        width: 70px;
        &.row--item{
          color: #00E279;
        }
      }

      .three {
        //width: 100px;
        flex: 1;
      }

      .four {
        width: 95px;
      }

      .five {
        //width: 36px;
        flex: 1;
      }
    }

    &__header {
      display: flex;
      height: 28px;
      line-height: 28px;
      background: rgba(21, 77, 160, 0.20);
      font-family: PingFangSC-Regular;
      font-size: 12px;
      color: #D8F0FF;
      letter-spacing: 0;
      font-weight: 400;

    }

    &__body {
      .row {
        height: 28px;
        line-height: 28px;
        display: flex;

        &.two {
          background-image: url('@/assets/images/armyScreen/通行记录_底纹@2x.png');
          background-size: cover;
        }

        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: rgba(216, 240, 255, 0.80);
        letter-spacing: 0;
        font-weight: 400;
      }
    }

    .scrollbarlist{
      width: 100%;
      animation: move 10s linear infinite normal;
      overflow-x: hidden;
      &:hover{
        animation-play-state:paused;
      }
    }
  }
}
@keyframes move {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(calc(-100% + 240px));
  }

}
</style>
